package com.liao.library.http.subscriber;

import com.liao.library.http.HttpExceptionMsg;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.subscribers.ResourceSubscriber;
import retrofit2.Response;

public abstract class CommonResponseSubscriber<T> extends ResourceSubscriber<Response<T>> {
    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void onNext(Response<T> t) {
        onSuccess(t);
    }

    @Override
    public void onError(Throwable t) {
        onFail(HttpExceptionMsg.exceptionHandler(t));
        onFinish();
    }

    @Override
    public void onComplete() {
        onFinish();
    }

    protected abstract void onSuccess(@NonNull Response<T> response);
    protected abstract void onFail(String msg);
    protected abstract void onFinish();
}
